package com.sun.interceptora;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义拦截器
 * @author sun
 */
public class MyInterceptor1 implements HandlerInterceptor {

    /**
     * 在目标方法之前运行
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("this is MyInterceptor1 ,method=preHandle");
        return true;
    }

    /**
     *业务处理器处理完请求后执行
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("this is MyInterceptor1 ,method=postHandle");
    }

    /**
     * 完全处理完请求后被调用
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("this is MyInterceptor1 ,method=afterCompletion");
    }
}
